<template>
  <!-- 地图 -->
  <el-dialog
    v-el-drag-dialog
    append-to-body
    title="位置查询"
    :visible.sync="visible"
    width="1024px"
    @closed="reset"
  >
    <baidu-map
      class="map"
      style="width: 100%; height: 500px;"
      :center="center"
      :zoom="zoom"
      :scroll-wheel-zoom="true"
      @ready="handler"
    >
      <!-- <bm-scale anchor="BMAP_ANCHOR_BOTTOM_LEFT" /> -->
      <bm-marker v-if="markerFlag" :position="position" animation="BMAP_ANIMATION_BOUNCE" />
    </baidu-map>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">
        关闭
      </el-button>
      <!-- <el-button :loading="$loadingPlugin.success" type="primary" @click="success">
        保存
      </el-button> -->
    </div>
  </el-dialog>
</template>

<script>

  export default {
    name: 'location',
    data() {
      return {
        visible: false,
        zoom: 12,
        markerFlag: false,
        temp: {
          address: ''
        },
        center: {
          lng: 0,
          lat: 0
        },
        point: {
          lng: 116.403765,
          lat: 39.914850
        }
      }
    },
    methods: {
      handler({ BMap, map }) {
        // console.log(BMap, map)
        this.center.lng = 114.298572
        this.center.lat = 30.584355
        this.zoom = 12
      },
      open(temp) {
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
          if (temp) {
            if (temp.latitude && temp.longitude) {
              this.position = {
                lat: temp.latitude,
                lng: temp.longitude
              }
              this.center = {
                lat: temp.latitude,
                lng: temp.longitude
              }
              this.markerFlag = true
            } else {
              this.markerFlag = false
            }
            console.log(temp, 'temp')
          }
        })
      },
      reset() {

      }
    }
  }
</script>

<style lang="scss" scoped>
.bm-view {
  width: 100%;
  height: 500px;
}
</style>
